import getApiData, { isCheckProjectIsOpened } from "@/services/cpasRequest";

export async function getZcbfList(params: {
    projectBh: string
}) {
    try {
        const res = await getApiData('pm.zcbfList', {
            projectBh: params.projectBh
        });
        if (res.ok) {
            return Promise.resolve({
                data: res.data,
                success: true,
            });
        }
        return Promise.resolve({
            data: res.data,
            success: false,
        });
    } catch (error) {
        return Promise.resolve({
            data: 'catch,报错了',
            success: true,
        });
    }
}
export async function getListData(params: {
    projectBh: string;
}) {
    try {
        const res = await getApiData('pm.list', params);
        if (res.code === 0) {
            return Promise.resolve({
                data: res.data,
                success: true,
            });
        }
        return Promise.resolve({
            data: res.data,
            success: false,
        });
    } catch (error) {
        return Promise.resolve({
            data: 'catch,报错了',
            success: true,
        });
    }
}


export async function getMembersList(params: {
    projectBh: string;
    XMType?: string;
}) {
    try {
        const res = await getApiData('pm.membersList', params);
        if (res.code === 0) {
            return Promise.resolve({
                data: res.data,
                success: true,
            });
        }
        return Promise.resolve({
            data: res.data,
            success: false,
        });
    } catch (error) {
        return Promise.resolve({
            data: 'catch,报错了',
            success: true,
        });
    }
}


export async function getPermission(params: {
    projectBh: string;
    usercode?: string;
    zcbfid?: string;
}) {
    try {
        const res = await getApiData('pm.getPermes', params);
        if (res.code === 0) {
            return Promise.resolve({
                data: res.data,
                success: true,
            });
        }
        return Promise.resolve({
            data: res.data,
            success: false,
        });
    } catch (error) {
        return Promise.resolve({
            data: 'catch,报错了',
            success: true,
        });
    }
}
export async function getCurrentZcbfInfo(params: {
    zcbfID?: string;
}) {
    try {
        const res = await getApiData('pm.currentZcbfInfo', params);
        if (res.code === 0) {
            return Promise.resolve({
                data: res.data,
                success: true,
            });
        }
        return Promise.resolve({
            data: res.data,
            success: false,
        });
    } catch (error) {
        return Promise.resolve({
            data: 'catch,报错了',
            success: true,
        });
    }
}




export async function getIsCheckProjectIsOpened(params: {
    projectBh?: string;
    zcbfid?: string[];
}) {
    try {
        const res = await isCheckProjectIsOpened(params);
        if (res.ok) {
            return Promise.resolve({
                data: res.data,
                success: true,
            });
        }
        return Promise.resolve({
            data: res.data,
            success: false,
        });
    } catch (error) {
        return Promise.resolve({
            data: 'catch,报错了',
            success: false,
        });
    }
}
/**
 * 获取单机项目列表
 * @returns [DBName,id,projectID,projectBh,projectName,sjxmbh,sjnd,projectState,
 * xmhhr,manager,quality,XMType,bsdw,xmTimeEnd,xmTimeStart]
 */
export async function getLocalProjectList() {
    const retData = await getApiData('pm.convertToLine.list', { xmType: '' }); //xmType:联机审计项目/单机审计项目,为空时全部显示
    if (retData.ok) {
        retData.data?.forEach((item: any) => {
            item.displayText = item.zcbfName /* + ' ' + item.sjxmbh + '' */
        })
        return retData.data
    }
    return [];
}
/**
 * 替换全角空格
 * @param str 
 * @returns 
 */
export function replaceFullSpace(str: string) {
    return str ? str.replaceAll('　', '') : str;
}



